<template>
	<view>
		<cu-custom bgColor="bg-red" :isBack="true">		<block slot="backText"></block>
			<block slot="content">团队业绩</block>
		</cu-custom>

		<view class="bg-blue overflow padding-lg text-white text-center relative">
			<view class="grid col-3 margin-tb">
				<view>
					<view class=" margin-bottom-sm">总业绩</view>
					<view class="text-xl text-bold marin-top">{{statistics?statistics.total:'-'}}</view>
				</view>
				<view>
					<view class=" margin-bottom-sm">当月新增业绩</view>
					<view class="text-xl text-bold marin-top">{{statistics?statistics.month:'-'}}</view>
				</view>
				<view>
					<view class=" margin-bottom-sm">当日新增业绩</view>
					<view class="text-xl text-bold marin-top">{{statistics?statistics.today:'-'}}</view>
				</view>
			</view>
		</view>
		<view class="cu-list bg-white">
			<block v-for="(item,index) in list" :key="index">
				<view class="padding solid-bottom margin-bottom">
					<view class="space-between dashed-bottom padding-bottom-sm margin-bottom-sm">
						<view>
							<image :src="item.baseMember.head_portrait" class="cu-avatar round"></image>
							{{item.baseMember.nickname}}
						</view>
						<view class="text-orange text-price">{{item.order_money}}</view>
					</view>
					<view v-for="(p,i) in item.product" :key="i">
						<view class="space-between margin-bottom-sm">
							<view>
								<image :src="p.product_picture" class="cu-avatar lg"></image>
							</view>
							<view class="w100 margin-left-sm">
								<view class="text-cut">{{p.product_name}}</view>
								<view class="margin-top-sm"><text class="text-price text-red magin-right">{{p.price}}</text> * {{p.num}}</view>
							</view>
						</view>
					</view>
					<view class="text-gray margin-top-xs">
						{{$common.timeFormat(item.created_at)}}
					</view>
				</view>
			</block>
		</view>

		<view class="cu-load margin-center" :class="loading?'loading':'over'"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				member: null,
				config: null,
				CLOUDPATH: this.$config.cloudPath,
				theme: this.$config.THEME(),
				TabCur: 0,
				list: [],
				hasMore: true,
				loading: false,
				page: 1,
				statistics: null,
			}
		},
		onLoad(options) {
			if (this.$common.loginAuth(true)) {
				this.$common.getConfig().then((config) => {
					this.config = config
					this.getList()
				})
				this.$common.getMember().then((member) => {
					this.member = member
				})
			}
			this.getStatistics()
		},
		onShow() {
			if (this.$common.loginAuth(true)) {}
		},
		methods: {
			getStatistics() {
				this.$http
					.get('team_achievement_statistics')
					.then((response) => {
						this.statistics = response.data.data
					})
					.catch((response) => {
						uni.hideLoading()
					})

			},
			getList() {
				if (this.hasMore && !this.loading) {
					this.loading = true
					this.$http
						.get('team_achievement', {
							team: 1,
							page: this.page
						})
						.then((response) => {
							let list = this.list
							if (response.data.data.length > 0) {
								list = list.concat(response.data.data)
							} else {
								this.hasMore = false
							}
							this.list = list
							this.page += 1

							this.loading = false
							uni.hideLoading()
						})
						.catch((response) => {
							uni.hideLoading()
						})

				}
			}
		},
		onReachBottom() {
			this.getList()
		}
	}
</script>

<style>
	.txbtn {
		min-width: 160rpx;
	}

	.loglg {
		right: 0;
		top: 30rpx;
		border-radius: 30rpx 0 0 30rpx;
	}

	.loglg2 {
		right: 0;
		top: 100rpx;
		border-radius: 30rpx 0 0 30rpx;
	}
</style>
